<!doctype html>
<html>
  <head>
    <title>XMLHttpRequest: send() - charset parameter of Content-Type</title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <link rel="help" href="https://xhr.spec.whatwg.org/#the-send()-method" data-tested-assertations="following::ol[1]/li[4]/p/code[contains(text(),'Content-Type')]/.. following::ol[1]/li[4]/p/code[contains(text(),'Content-Type')]/../following-sibling::p" />
    <link rel="help" href="https://xhr.spec.whatwg.org/#dom-XMLHttpRequest-send-a-string" data-tested-assertations="following::p[2]" />
  </head>
  <body>
    <div id="log"></div>
    <script>
      function request(input, output) {
        test(function() {
        var client = new XMLHttpRequest()
        client.open("POST", "resources/content.py", false)
        if(input)
          client.setRequestHeader("Content-Type", input)
        client.send("TEST")
        assert_equals(client.responseText, "TEST")
        assert_equals(client.getResponseHeader("x-request-content-type"), output)
        })
      }
      request(
        "text/x-pink-unicorn; charset=windows-1252; charset=bogus; notrelated; charset=ascii",
        "text/x-pink-unicorn; charset=UTF-8; charset=UTF-8; notrelated; charset=UTF-8"
      )
      request(
        "text; charset=ascii",
        "text; charset=ascii"
      )
      request(
        "charset=ascii",
        "charset=ascii"
      )
      request(
        "text/x-thepiano;charset= waddup",
        "text/x-thepiano;charset=UTF-8"
      )
      request(
        "text/x-pink-unicorn",
        "text/x-pink-unicorn"
      )
      request(
        "text/plain;charset=utf-8",
        "text/plain;charset=utf-8"
      )
      request(
        "text/plain;charset=utf-8;charset=waddup",
        "text/plain;charset=UTF-8;charset=UTF-8"
      )
      request(
        null,
        "text/plain;charset=UTF-8"
      )
    </script>
  </body>
</html>
